<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/style/admin.css" media="all">
</head>

<body>

    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">附件更换</div>
                    <div class="layui-card-body">
                        <table class="layui-hide" id="accessory-replace-table" lay-filter="accessory-replace-table">
                        </table>
                        <script type="text/html" id="toolbar-operation">
                        <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="/layui/layui.js"></script>
    <script src="/js/common.js"></script>
    <script>
        layui.config({
            base: '/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form'], function () {
            var $ = layui.$;
            var table = layui.table;
            var form = layui.form;
            var admin = layui.admin;
            var accessoryId = getParam("accessoryId");
            var popupIndex;

            table.render({
                elem: '#accessory-replace-table',
                url: 'accessory-replaces',
                title: '',
                skin: 'line',
                cols: [[
                    { type: 'checkbox' },
                    {
                        title: '序号', width: 60, templet: function (d) {
                            return d.LAY_TABLE_INDEX + 1;
                        }
                    },
                    { field: 'info1', title: '更换前' },
                    { field: 'info2', title: '更换后' },
                    { field: 'replaceTime', title: '更换时间' },
                    { fixed: 'right', title: '操作', toolbar: '#toolbar-operation' }
                ]],
                where: {
                    accessoryId: accessoryId
                },
                page: true
            });

            $("#btn-refresh").on('click', function () {
                table.reload('accessory-replace-table');
                layer.msg('表格已刷新');
            });

            table.on('tool(accessory-replace-table)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('真的删除该记录吗？', function (index) {
                        $.ajax({
                            url: 'accessory-replaces/' + data.id,
                            type: 'DELETE',
                            success: function (result) {
                                if (result.code == 200) {
                                    layer.msg('删除成功');
                                    table.reload('accessory-replace-table');
                                } else {
                                    layer.msg('删除失败');
                                }
                            }
                        });
                        layer.close(index);
                    });
                } else if (obj.event === 'detail') {
                    layer.open({
                        title: '附件更换详情',
                        type: 2,
                        content: 'accessory-replace-info.html?id=' + data.id,
                        area: ['960px', '620px'],
                        maxmin: true
                    });
                }
            });

        });
    </script>
</body>

</html>